local weifu = fk.CreateSkill {
  name = "lingling__weifu",
  tags = { Skill.Compulsory },
  dynamic_desc = function (self, player)
    if #player:getTableMark(self.name) == 0 then
      return "dummyskill"
    else
      local choices = {}
      for i = 1, 3, 1 do
        if table.contains(player:getTableMark(self.name), i) then
          table.insert(choices, Fk:translate("lingling__weifu"..i))
        else
          table.insert(choices, "<font color=\'gray\'>"..Fk:translate("lingling__weifu"..i).."</font>")
        end
      end
      return "lingling__weifu_inner:"..table.concat(choices, "")
    end
  end,
}

Fk:loadTranslationTable{
  ["lingling__weifu"] = "威福",
  [":lingling__weifu"] = "锁定技，当你受到技能伤害后，你摸三张牌。当你受到虚拟牌伤害后，你摸两张牌。当你受到转化牌伤害后，你摸一张牌。",

  [":lingling__weifu_inner"] = "锁定技，{1}",
  ["lingling__weifu1"] = "当你受到技能伤害后，你摸三张牌。",
  ["lingling__weifu2"] = "当你受到虚拟牌伤害后，你摸两张牌。",
  ["lingling__weifu3"] = "当你受到转化牌伤害后，你摸一张牌。",
}

weifu:addEffect(fk.Damaged, {
  anim_type = "masochism",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(weifu.name) then
      if not data.card then
        return table.contains(player:getTableMark(weifu.name), 1)
      elseif data.card:isVirtual() and #data.card.subcards == 0 then
        return table.contains(player:getTableMark(weifu.name), 2)
      elseif data.card:isVirtual() and #data.card.subcards > 0 then
        return table.contains(player:getTableMark(weifu.name), 3)
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local n = 0
    if not data.card then
      n = 3
    elseif data.card:isVirtual() and #data.card.subcards == 0 then
      n = 2
    elseif data.card:isVirtual() and #data.card.subcards > 0 then
      n = 1
    end
    player:drawCards(n, weifu.name)
  end,
})

weifu:addAcquireEffect(function (self, player, is_start)
  player.room:setPlayerMark(player, weifu.name, {1, 2, 3})
end)

weifu:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, weifu.name, 0)
end)

return weifu
